package com.zkadmin.constraints;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.zkoss.util.resource.Labels;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;

public class ZulPageConstraint implements Constraint {

	@Override
	public void validate(Component comp, Object value) throws WrongValueException {
		if (value != null) {
			String v = (String) value;
			if (!v.trim().equals("")) {
				Pattern pattern = Pattern.compile("(\\s?|[\\w\\/]*[a-z0-9].zul)");
				Matcher matcher = pattern.matcher(v);
				if (!matcher.matches()) {
					throw new WrongValueException(comp, Labels.getLabel("error.onlyzul.message"));
				}
			}
		}
	}
}
